$(function () {
    function ajax(url, data) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: url,
                success(data) {
                    resolve(data);
                },
                error(data) {
                    reject(data);
                },
            });
        });
    }
    /////////////////////////////////////////////////////////////////
    var code, hero, heroPrice;
    ajax("data/hero.json", null)
        .then(data => {
            ({ code: code, data: hero } = data);
            if (code == 200) {
                var lis = "";
                for (item of hero) {
                    lis += item["id"]
                }
                return ajax("data/hero_price.json", lis);
            }
        })
        .then(data => {
            ({ code: code, data: heroPrice } = data);
            if (code == 200) {
                var lis = "";
                for (item of hero) {
                    $.extend(item, heroPrice[item["id"]]);
                    lis += `
                            <li>
                                <a href='###' class='img'><img src='${item["img"]}' alt=''><span class='mask'></span><span class='name'>${item["name"]}</span><span class='coin'>${item["coin"]}</span><span class='diamond'>${item["diamond"]}</span></a>
                                <a href='###' class='buy'>购买</a>
                            </li>
                            `;
                }
                ul = "<ul>" + lis + "</ul>";
                $(".con").html(ul);
            }
        })

});

